﻿' ///////////////////////////////////////////////////////////////
' // This is generated code. 
' //////////////////////////////////////////////////////////////
' // Code is generated using LLBLGen Pro version: 2.6
' // Code is generated on: lundi 28 septembre 2009 23:24:57
' // Code is generated using templates: SD.TemplateBindings.SqlServerSpecific.NET20
' // Templates vendor: Solutions Design.
' // Templates version: 
' //////////////////////////////////////////////////////////////
Imports System
Imports System.Collections
Imports System.Data
Imports System.Data.Common
#If CF Then
Imports System.Data.SqlServerCe
#Else
Imports System.Data.SqlClient
#End If

#If Not CF Then
Imports System.EnterpriseServices
Imports System.Configuration
#End If

Imports SD.LLBLGen.Pro.ORMSupportClasses
Imports SD.LLBLGen.Pro.DQE.SqlServer


' __LLBLGENPRO_USER_CODE_REGION_START AdditionalNamespaces
' __LLBLGENPRO_USER_CODE_REGION_END


Namespace Aricie.DNN.Services.Url.FriendlyUrl.DatabaseSpecific
	''' <summary>
	''' Data access adapter class, which controls the complete database interaction with the database for all objects.
	''' SqlServer specific.
	''' </summary>
	''' <remarks>
	''' Use a DataAccessAdapter object solely per thread, and per connection. A DataAccessAdapter object contains 1 active connection 
	''' and no thread-access scheduling code. This means that you need to create a New DataAccessAdapter object if you want to utilize
	''' in another thread a New connection and a New transaction or want to open a New connection.
	''' </remarks>
	Public Class DataAccessAdapter 
		Inherits DataAccessAdapterBase
	
#If Not CF Then	
#Region "Public Shared members"
		''' <summary>
		''' The name of the key in the *.config file of the executing application which contains the connection string.
		''' </summary>
		''' <remarks>Default: the value Set in the LLBLGen Pro project properties</remarks>
		Public Shared ConnectionStringKeyName As String = "SiteSqlServer"
#End Region
#End If
		
#Region "Class Member Declarations"
		'  SqlServer specific information about catalog name usage
		Private _catalogNameOverwrites As CatalogNameOverwriteHashtable
		Private _schemaNameOverwrites As SchemaNameOverwriteHashtable
#End Region

#Region "Constructors"
		''' <summary>
		''' CTor
		''' </summary>
		Public Sub New()
			MyBase.New(PersistenceInfoProviderSingleton.GetInstance())
#If CF Then
			InitClass(String.Empty, False, CatalogNameUsage.Default, String.Empty, Nothing, Nothing)
#Else
			InitClass(ReadConnectionStringFromConfig(), False, CatalogNameUsage.Default, String.Empty, Nothing, Nothing)
#End If
		End Sub

#If Not CF Then
		''' <summary>
		''' CTor
		''' </summary>
		''' <param name="comPlusContextHost">the COM+ context host for this adapter instance.</param>
		''' <remarks>do not call this from your code</remarks>
		Public Sub New(comPlusContextHost As IComPlusAdapterContext)
			MyBase.New(comPlusContextHost, PersistenceInfoProviderSingleton.GetInstance())
			InitClass(ReadConnectionStringFromConfig(), False, CatalogNameUsage.Default, String.Empty, Nothing, Nothing)
		End Sub


		''' <summary>
		''' CTor
		''' </summary>
		''' <param name="comPlusContextHost">the COM+ context host for this adapter instance.</param>
		''' <param name="connectionString">The connection string to use when connecting to the database.</param>
		''' <remarks>do not call this from your code</remarks>
		Public Sub New(comPlusContextHost As IComPlusAdapterContext, connectionString As String)
			MyBase.New(comPlusContextHost, PersistenceInfoProviderSingleton.GetInstance())
			InitClass(connectionString, False, CatalogNameUsage.Default, String.Empty, Nothing, Nothing)
		End Sub
#End If		

		''' <summary>
		''' CTor
		''' </summary>
		''' <param name="keepConnectionOpen">when True, the DataAccessAdapter will not close an opened connection. Use this for multi action usage.</param>
		Public Sub New(keepConnectionOpen As Boolean)
			MyBase.New(PersistenceInfoProviderSingleton.GetInstance())
#If CF Then
			InitClass(String.Empty, keepConnectionOpen, CatalogNameUsage.Default, String.Empty, Nothing, Nothing)
#Else
			InitClass(ReadConnectionStringFromConfig(), keepConnectionOpen, CatalogNameUsage.Default, String.Empty, Nothing, Nothing)
#End If			
		End Sub


		''' <summary>
		''' CTor
		''' </summary>
		''' <param name="connectionString">The connection string to use when connecting to the database.</param>
		Public Sub New(connectionString As String)
			MyBase.New(PersistenceInfoProviderSingleton.GetInstance())
			InitClass(connectionString, False, CatalogNameUsage.Default, String.Empty, Nothing, Nothing)
		End Sub


		''' <summary>
		''' CTor
		''' </summary>
		''' <param name="connectionString">The connection string to use when connecting to the database.</param>
		''' <param name="keepConnectionOpen">when True, the DataAccessAdapter will not close an opened connection. Use this for multi action usage.</param>
		Public Sub New(connectionString As String, keepConnectionOpen As Boolean)
			MyBase.New(PersistenceInfoProviderSingleton.GetInstance())
			InitClass(connectionString, keepConnectionOpen, CatalogNameUsage.Default, String.Empty, Nothing, Nothing)
		End Sub
		
		
		''' <summary>
		''' CTor. SqlServer specific
		''' </summary>
		''' <param name="connectionString">The connection string to use when connecting to the database.</param>
		''' <param name="keepConnectionOpen">when True, the DataAccessAdapter will not close an opened connection. Use this for multi action usage.</param>
		''' <param name="catalogNameUsageSetting">SqlServer specific. Configures this data access adapter object how to threat catalog names in 
		''' persistence information.</param>
		''' <param name="catalogNameToUse">SqlServer specific. The name to use if catalogNameUsageSetting is Set to ForceName. Ignored otherwise.</param>
		''' <remarks>For backwards compatibility.</remarks>
		Public Sub New(connectionString As String, keepConnectionOpen As Boolean, catalogNameUsageSetting As CatalogNameUsage, catalogNameToUse As String)
			MyBase.New(PersistenceInfoProviderSingleton.GetInstance())
			InitClass(connectionString, keepConnectionOpen, catalogNameUsageSetting, catalogNameToUse, Nothing, Nothing)
		End Sub


		''' <summary>
		''' CTor. SqlServer specific
		''' </summary>
		''' <param name="connectionString">The connection string to use when connecting to the database.</param>
		''' <param name="keepConnectionOpen">when True, the DataAccessAdapter will not close an opened connection. Use this for multi action usage.</param>
		''' <param name="catalogNameOverwrites">SqlServer specific. The from-To name value pairs And setting For the overwriting of catalog names. Can be null.</param>
		''' <param name="schemaNameOverwrites">SqlServer specific. The from-To name value pairs And setting For the overwriting of schema names. Can be null.</param>
		Public Sub New (connectionString As String, keepConnectionOpen As Boolean, catalogNameOverwrites As CatalogNameOverwriteHashtable, _
			schemaNameOverwrites As SchemaNameOverwriteHashtable)
			MyBase.New(PersistenceInfoProviderSingleton.GetInstance())
			InitClass(connectionString, keepConnectionOpen, CatalogNameUsage.Default, String.Empty, catalogNameOverwrites, schemaNameOverwrites)
		End Sub
#End Region

#If Not CF Then
#Region "Stored Procedure related routines"
		''' <summary>
		''' Calls the specified action stored procedure in the SqlServer database. If a transaction is in progress, it will participate in
		''' that transaction.
		''' </summary>
		''' <param name="storedProcedureToCall">Stored procedure to call</param>
		''' <param name="parameters">array of parameters to specify</param>
		''' <returns>the amount of rows affected. This value will be -1 if the stored procedure sets ROWCOUNT to OFF or this has
		''' been disabled in the catalog by other settings.</returns>
		Public Overridable Function CallActionStoredProcedure(storedProcedureToCall As String, parameters() As SqlParameter) As Integer
			Dim Command As New SqlCommand(CreateCorrectStoredProcedureName(storedProcedureToCall))
			Command.Connection = CType(MyBase.GetActiveConnection(), SqlConnection)
			If MyBase.IsTransactionInProgress Then
				Command.Transaction = CType(MyBase.PhysicalTransaction, SqlTransaction)
			End If
			Command.CommandType = CommandType.StoredProcedure
			Command.CommandTimeout = MyBase.CommandTimeOut

			Dim toReturn As Integer = -1
			Try
				Dim i As Integer
				For i=0 To parameters.Length-1
					Command.Parameters.Add(parameters(i))
				Next i

				MyBase.OpenConnection()
				toReturn = Command.ExecuteNonQuery()
			Finally
				command.Dispose()
				'  clean up a dangling automaticly opened connection if needed.
				If Not (MyBase.KeepConnectionOpen Or MyBase.IsTransactionInProgress) Then
					MyBase.CloseConnection()
				End If
			End Try
			Return toReturn
		End Function


		''' <summary>
		''' Calls the specified retrieval stored procedure in the SqlServer database. Fills the
		''' specified datatable. Will participate in the transaction if a transaction is in progress.
		''' </summary>
		''' <param name="storedProcedureToCall">Stored procedure to call</param>
		''' <param name="parameters">array of parameters to specify</param>
		''' <param name="tableToFill">Datatable to fill by the stored procedure</param>
		''' <returns>True if succeeded, False otherwise</returns>
		Public Overridable Function CallRetrievalStoredProcedure(storedProcedureToCall As String, parameters() As SqlParameter, tableToFill As DataTable) As Boolean
			Dim Command As New SqlCommand(CreateCorrectStoredProcedureName(storedProcedureToCall))
			Command.Connection = CType(MyBase.GetActiveConnection(), SqlConnection)
			If MyBase.IsTransactionInProgress Then
				Command.Transaction = CType(MyBase.PhysicalTransaction, SqlTransaction)
			End If
			Command.CommandType = CommandType.StoredProcedure
			Command.CommandTimeout = MyBase.CommandTimeOut

			Try
				Dim adapter As SqlDataAdapter = CType(CreateNewPhysicalDataAdapter(), SqlDataAdapter)
				adapter.SelectCommand = Command
				Dim i As Integer
				For i=0 To parameters.Length-1
					Command.Parameters.Add(parameters(i))
				Next i
				adapter.Fill(tableToFill)
				adapter.Dispose()
			Finally
				command.Dispose()
			End Try
			Return True
		End Function


		''' <summary>
		''' Calls the specified retrieval stored procedure in the SqlServer database. Fills the
		''' specified DataSet. Will participate in the transaction if a transaction is in progress.
		''' </summary>
		''' <param name="storedProcedureToCall">Stored procedure to call</param>
		''' <param name="parameters">array of parameters to specify</param>
		''' <param name="dataSetToFill">DataSet to fill by the stored procedure</param>
		''' <returns>True if succeeded, False otherwise</returns>
		Public Overridable Function CallRetrievalStoredProcedure(storedProcedureToCall As String, parameters() As SqlParameter, dataSetToFill As DataSet) As Boolean
			Dim Command As New SqlCommand(CreateCorrectStoredProcedureName(storedProcedureToCall))
			Command.Connection = CType(MyBase.GetActiveConnection(), SqlConnection)
			If MyBase.IsTransactionInProgress Then
				Command.Transaction = CType(MyBase.PhysicalTransaction, SqlTransaction)
			End If
			Command.CommandType = CommandType.StoredProcedure
			Command.CommandTimeout = MyBase.CommandTimeOut

			Try
				Dim adapter As SqlDataAdapter = CType(CreateNewPhysicalDataAdapter(), SqlDataAdapter)
				adapter.SelectCommand = Command

				Dim i As Integer
				For i=0 To parameters.Length-1
					Command.Parameters.Add(parameters(i))
				Next i
				adapter.Fill(dataSetToFill)
				adapter.Dispose()
			Finally
				command.Dispose()
			End Try
			Return True
		End Function
#End Region

		''' <summary>
		''' Sets the flag to signal the SqlServer DQE to generate SET ARITHABORT ON statements prior to INSERT, DELETE and UPDATE Queries.
		''' Keep this flag to false in normal usage, but set it to true if you need to write into a table which is part of an indexed view.
		''' It will not affect normal inserts/updates that much, leaving it on is not harmful. See Books online for details on SET ARITHABORT ON.
		''' After each statement the setting is turned off if it has been turned on prior to that statement.
		''' </summary>
		''' <remarks>Setting this flag is a global change.</remarks>
		Public Shared Sub SetArithAbortFlag(value As Boolean)
			SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.ArithAbortOn = value
		End Sub
		
		''' <summary>
		''' Compatibility level used by the DQE. Default Is SqlServer2000. To utilize SqlServer 2005 specific features, Set this parameter 
		''' To SqlServer2005, either through a setting In the .config file of your application Or by setting this parameter once In your application.
		''' Compatibility level influences the query generated For paging, sequence name (@@IDENTITY/SCOPE_IDENTITY()), And usage of newsequenceid() In inserts. 
		''' It also influences the provider To use. This way you can switch between SqlServer server client 'SqlClient' and SqlServer CE Desktop. 
		''' </summary>
		''' <remarks>Setting this Property will overrule a similar setting In the .config file. Don't set this property when queries are executed as
		''' it might switch factories For ADO.NET elements which could result In undefined behavior. Set this Property at startup of your application As it's
		''' a global setting (affects all queries In your application using this DQE)</remarks>
		Public Shared Sub SetSqlServerCompatibilityLevel(compatibilityLevel As SqlServerCompatibilityLevel)
			SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CompatibilityLevel = compatibilityLevel
		End Sub


		''' <summary>
		''' Executes the passed In retrievalquery And returns an open, ready To use IDataReader. The datareader's command behavior is set to the
		''' readerBehavior passed In. If a transaction Is In progress, the Command Is wired To the transaction.
		''' </summary>
		''' <param name="queryToExecute">The query To execute.</param>
		''' <param name="readerBehavior">The reader behavior To Set.</param>
		''' <returns>Open, ready To use IDataReader</returns>
		''' <remarks>Advanced functionality: be aware that the datareader returned Is open, And the dataaccessadapter's connection is also open</remarks>
		Public Overrides Function FetchDataReader(queryToExecute As IRetrievalQuery, readerBehavior As CommandBehavior) As IDataReader
			If queryToExecute.Command.CommandType = CommandType.StoredProcedure Then
				queryToExecute.Command.CommandText = CreateCorrectStoredProcedureName(queryToExecute.Command.CommandText)
			End If
			Return MyBase.FetchDataReader(queryToExecute, readerBehavior)
		End Function
#End If

		''' <summary>
		''' Inserts in each predicate expression element the persistence info object for the field used. If there is already a fieldpersistenceinfo 
		''' element for a given field, it is skipped. 
		''' </summary>
		''' <param name="expression">IPredicateExpression object which has predicate elements whose persistence info objects have to be
		''' Set to a value.</param>
		Protected Overloads Overrides Sub InsertPersistenceInfoObjects(expression As IPredicateExpression)
			If expression Is Nothing Then
				Return
			End If

			Dim i As Integer
			For i = 0 To expression.Count-1
				If expression(i).Type = PredicateExpressionElementType.Predicate Then
					Dim currentPredicate As IPredicate = CType(expression(i).Contents, IPredicate)
					
					Select Case CType(currentPredicate.InstanceType, PredicateType)
						Case PredicateType.PredicateExpression
							'  recurse
							InsertPersistenceInfoObjects(CType(expression(i).Contents, IPredicateExpression))
						Case PredicateType.FieldBetweenPredicate
							Dim betweenPredicate As FieldBetweenPredicate = CType(currentPredicate, FieldBetweenPredicate)
							If betweenPredicate.PersistenceInfo Is Nothing Then
								betweenPredicate.PersistenceInfo = GetFieldPersistenceInfo(CType(betweenPredicate.FieldCore, IEntityField2))
							End If
							If betweenPredicate.BeginIsField AndAlso (betweenPredicate.PersistenceInfoBegin Is Nothing) Then
								betweenPredicate.PersistenceInfoBegin = GetFieldPersistenceInfo(CType(betweenPredicate.FieldBeginCore, IEntityField2))
							End If
							If betweenPredicate.EndIsField AndAlso (betweenPredicate.PersistenceInfoEnd Is Nothing) Then
								betweenPredicate.PersistenceInfoEnd = GetFieldPersistenceInfo(CType(betweenPredicate.FieldEndCore, IEntityField2))
							End If
						Case PredicateType.FieldCompareNullPredicate
							Dim compareNullPredicate As FieldCompareNullPredicate = CType(currentPredicate, FieldCompareNullPredicate)
							If compareNullPredicate.PersistenceInfo Is Nothing Then
								compareNullPredicate.PersistenceInfo = GetFieldPersistenceInfo(CType(compareNullPredicate.FieldCore, IEntityField2))
							End If
						Case PredicateType.FieldCompareValuePredicate
							Dim compareValuePredicate As FieldCompareValuePredicate = CType(currentPredicate, FieldCompareValuePredicate)
							If compareValuePredicate.PersistenceInfo Is Nothing Then
								compareValuePredicate.PersistenceInfo = GetFieldPersistenceInfo(CType(compareValuePredicate.FieldCore, IEntityField2))
							End If
						Case PredicateType.FieldLikePredicate
							Dim likePredicate As FieldLikePredicate = CType(currentPredicate, FieldLikePredicate)
							If likePredicate.PersistenceInfo Is Nothing Then
								likePredicate.PersistenceInfo = GetFieldPersistenceInfo(CType(likePredicate.FieldCore, IEntityField2))
							End If
						Case PredicateType.FieldCompareRangePredicate
							Dim compareRangePredicate As FieldCompareRangePredicate = CType(currentPredicate, FieldCompareRangePredicate)
							If compareRangePredicate.PersistenceInfo Is Nothing Then
								compareRangePredicate.PersistenceInfo = GetFieldPersistenceInfo(CType(compareRangePredicate.FieldCore, IEntityField2))
							End If
						Case PredicateType.FieldCompareExpressionPredicate
							Dim expressionPredicate As FieldCompareExpressionPredicate = CType(currentPredicate, FieldCompareExpressionPredicate)
							If expressionPredicate.PersistenceInfo Is Nothing Then
								expressionPredicate.PersistenceInfo = GetFieldPersistenceInfo(CType(expressionPredicate.FieldCore, IEntityField2))
							End If
							
							If Not expressionPredicate.ExpressionToCompareWith Is Nothing Then
								InsertPersistenceInfoObjects(expressionPredicate.ExpressionToCompareWith)
							End If
						Case PredicateType.FieldFullTextSearchPredicate
							Dim fullTextSearchPredicate As FieldFullTextSearchPredicate = CType(currentPredicate, FieldFullTextSearchPredicate)
							If fullTextSearchPredicate.TargetIsFieldList Then
								If fullTextSearchPredicate.PersistenceInfosFieldsList Is Nothing Then
									Dim persistenceInfos As New ArrayList()
									For Each field As IEntityField2 In fullTextSearchPredicate.FieldsList
										persistenceInfos.Add(GetFieldPersistenceInfo(field))
									Next
									fullTextSearchPredicate.PersistenceInfosFieldsList = persistenceInfos
								End If
							Else
								If fullTextSearchPredicate.PersistenceInfo Is Nothing Then
									fullTextSearchPredicate.PersistenceInfo = GetFieldPersistenceInfo(CType(fullTextSearchPredicate.FieldCore, IEntityField2))
								End If
							End If
						Case PredicateType.FieldCompareSetPredicate
							Dim compareSetPredicate As FieldCompareSetPredicate = CType(currentPredicate, FieldCompareSetPredicate)
							If compareSetPredicate.PersistenceInfoField Is Nothing AndAlso Not compareSetPredicate.FieldCore Is Nothing Then
								compareSetPredicate.PersistenceInfoField = GetFieldPersistenceInfo(CType(compareSetPredicate.FieldCore, IEntityField2))
							End If
							If compareSetPredicate.PersistenceInfoSetField Is Nothing Then
								compareSetPredicate.PersistenceInfoSetField = GetFieldPersistenceInfo(CType(compareSetPredicate.SetFieldCore, IEntityField2))
							End If
							InsertPersistenceInfoObjects(compareSetPredicate.SetFilterAsPredicateExpression)
							InsertPersistenceInfoObjects(compareSetPredicate.SetRelations)
							InsertPersistenceInfoObjects(compareSetPredicate.SetSorter)
							InsertPersistenceInfoObjects(compareSetPredicate.GroupByClause)
						Case Else
							
							' __LLBLGENPRO_USER_CODE_REGION_START InsertPersistenceInfoObjectsPredicate
							' __LLBLGENPRO_USER_CODE_REGION_END
							OnInsertPersistenceObjects(currentPredicate)
					End Select
				End If
			Next i
		End Sub

		''' <summary>
		''' Creates a New Dynamic Query engine Object And passes In the defined catalog/schema overwrite hashtables.
		''' </summary>
		Protected Overrides Function CreateDynamicQueryEngine() As DynamicQueryEngineBase
			Dim toReturn As New DynamicQueryEngine()
			toReturn.PerCallCatalogNameOverwrites = _catalogNameOverwrites
			toReturn.PerCallSchemaNameOverwrites = _schemaNameOverwrites
			Return CType(toReturn, DynamicQueryEngineBase)
		End Function


		''' <summary>
		''' Creates a New physical connection object.
		''' </summary>
		''' <param name="connectionString">Connectionstring to use for the New connection object</param>
		''' <returns>IDbConnection implementing connection object.</returns>
		Protected Overrides Function CreateNewPhysicalConnection(connectionString As String) As IDbConnection
#If CF Then
			Return New SqlCeConnection(connectionString)
#Else
			Dim toReturn As DbConnection = SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.FactoryToUse.CreateConnection()
			toReturn.ConnectionString = connectionString
			Return toReturn
#End If
		End Function


		''' <summary>
		''' Creates a New physical transaction object over the created connection. The connection is assumed to be open.
		''' </summary>
		''' <returns>a physical transaction object, like an instance of SqlTransaction.</returns>
		Protected Overrides Function CreateNewPhysicalTransaction() As IDbTransaction
#If CF Then
			Return CType(MyBase.GetActiveConnection(), SqlCeConnection).BeginTransaction(MyBase.TransactionIsolationLevel)
#Else
			Return MyBase.GetActiveConnection().BeginTransaction(MyBase.TransactionIsolationLevel)
#End If
		End Function


		''' <summary>
		''' Creates a New .NET DataAdapter for the database system this DataAccessAdapter object is targeting. 
		''' </summary>
		''' <returns>New .NET DataAdapter object</returns>
		Protected Overloads Overrides Function CreateNewPhysicalDataAdapter() As DbDataAdapter
#If CF Then
			Return New SqlCeDataAdapter()
#Else
			Return SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.FactoryToUse.CreateDataAdapter()
#End If
		End Function


		''' <summary>
		''' Initializes the class.
		''' </summary>
		''' <param name="connectionString"></param>
		''' <param name="keepConnectionOpen"></param>
		''' <param name="catalogNameUsageSetting"></param>
		''' <param name="catalogNameToUse"></param>
		''' <param name="catalogNameOverwrites"></param>
		''' <param name="schemaNameOverwrites"></param>
		Private Sub InitClass(connectionString As String, keepConnectionOpen As Boolean, catalogNameUsageSetting As CatalogNameUsage, catalogNameToUse As String, _
			catalogNameOverwrites As CatalogNameOverwriteHashtable, schemaNameOverwrites As SchemaNameOverwriteHashtable)
			MyBase.ConnectionString = connectionString
			MyBase.KeepConnectionOpen = keepConnectionOpen

			If catalogNameOverwrites Is Nothing Then
				_catalogNameOverwrites = New CatalogNameOverwriteHashtable(catalogNameUsageSetting)
				If catalogNameUsageSetting <> CatalogNameUsage.Default Then
					_catalogNameOverwrites.Add("*", catalogNameToUse)
				Else
					MyBase.ReadHandleCatalogNameSettingFromConfig(_catalogNameOverwrites)
				End If
			Else
				_catalogNameOverwrites = catalogNameOverwrites
			End If
			_schemaNameOverwrites = schemaNameOverwrites
		End Sub

#If Not CF Then
		''' <summary>
		''' Reads the value of the setting with the key ConnectionStringKeyName from the *.config file and stores that value as the
		''' active connection string to use for this object.
		''' </summary>
		''' <returns>connection string read</returns>
		Private Function ReadConnectionStringFromConfig() As String
			Return ConfigFileHelper.ReadConnectionStringFromConfig( DataAccessAdapter.ConnectionStringKeyName)

		End Function

		''' <summary>
		''' Creates the correct name of the stored procedure To Call, thus With schema/catalog name overwrites. 
		''' </summary>
		''' <param name="storedProcedureName">Name of the stored procedure.</param>
		''' <returns>stored procedure name With the catalog/schema name overwritten, If applicable</returns>
		Private Function CreateCorrectStoredProcedureName(storedProcedureName As String ) As String
			Dim dqe As DynamicQueryEngine = CType(CreateDynamicQueryEngine(), DynamicQueryEngine)
			Dim procName As String = dqe.GetNewPerCallStoredProcedureName(storedProcedureName)
			Return DynamicQueryEngine.GetNewStoredProcedureName(procName)
		End Function
#end if
		
#Region "Class Property Declarations"
		
		''' <summary>
		''' SqlServer specific. Configurates this data access adapter object how to threat catalog names in persistence information.
		''' </summary>
		''' <remarks>For backwards compatibility.</remarks>
		Public Property CatalogNameUsageSetting() As CatalogNameUsage
			Get
				If Not _catalogNameOverwrites Is Nothing Then
					Return _catalogNameOverwrites.CatalogNameUsageSetting
				Else
					Return CatalogNameUsage.Default
				End If
			End Get
			Set
				If Not _catalogNameOverwrites Is Nothing Then
					_catalogNameOverwrites.CatalogNameUsageSetting = value
				End If
			End Set
		End Property
		
		''' <summary>
		''' SqlServer specific. The name to use if catalogNameUsageSetting is Set to ForceName. Ignored otherwise.
		''' </summary>
		''' <remarks>For backwards compatibility.</remarks>
		Public Property CatalogNameToUse() As String
			Get
				If Not _catalogNameOverwrites Is Nothing AndAlso _catalogNameOverwrites.ContainsKey("*") Then
					Return CType(_catalogNameOverwrites("*"), String)
				Else
					Return String.Empty
				End If
			End Get
			Set
				If Not _catalogNameOverwrites Is Nothing Then
					If _catalogNameOverwrites.ContainsKey("*") Then
						_catalogNameOverwrites("*") = value
					Else
						_catalogNameOverwrites.Add("*", value)
					End If
				End If
			End Set
		End Property


		''' <summary>
		''' SqlServer specific. The from-To name value pairs And setting For the overwriting of catalog names.
		''' </summary>
		Public Property CatalogNameOverwrites As CatalogNameOverwriteHashtable
			Get 
				Return _catalogNameOverwrites 
			End Get
			Set 
				_catalogNameOverwrites = value
			End Set
		End Property

		
		''' <summary>
		''' SqlServer specific. The from-To name value pairs And setting For the overwriting of schema names.
		''' </summary>
		Public Property SchemaNameOverwrites As SchemaNameOverwriteHashtable
			Get 
				Return _schemaNameOverwrites 
			End Get
			Set 
				_schemaNameOverwrites = value
			End Set
		End Property

#End Region

#Region "Custom DataAccessAdapter code"
		
		' __LLBLGENPRO_USER_CODE_REGION_START CustomDataAccessAdapterCode
		' __LLBLGENPRO_USER_CODE_REGION_END
#End Region

#Region "Included Code"

#End Region
	End Class


#If Not CF Then
	''' <summary>
	''' ComPlusAdapterContext class which is used in Adapter for hosting a COM+ aware DataAccessAdapter class. 
	''' Use the hosted DataAccessAdapter class to start a new COM+ transaction.
	''' </summary>
	Public Class ComPlusAdapterContext 
		Inherits ComPlusAdapterContextBase

		''' <summary>
		''' CTor
		''' </summary>
		Public Sub New()
			MyBase.SetAdapter(New DataAccessAdapter(Me))
		End Sub

		''' <summary>
		''' Creates the physical connection object
		''' </summary>
		''' <param name="connectionString">connection string to use</param>
		''' <returns>Usable connection object (closed)</returns>
		Protected Overrides Overloads Function CreateDatabaseConnection(connectionString As String) As IDbConnection
			Return New SqlConnection(connectionString)
		End Function
	End Class
#End If	
End Namespace
